package com.mmall.controller.common;

import com.mmall.util.PropertiesUtil;
import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
@Slf4j
public class RedissonManager {

    private Config config = new Config();
    private Redisson redisson = null;
    private static Integer Prot1 = Integer.parseInt(PropertiesUtil.getProperty("redis1.prot"));
    private static String Ip1 = PropertiesUtil.getProperty("redis1.ip");

    @PostConstruct
    private void init() {
        try {
            config.useSingleServer().setAddress(new StringBuffer().append(Ip1).append(":").append(Prot1).toString());
            Redisson redisson = (Redisson) Redisson.create(config);
            this.redisson = redisson;
            log.info("初始化Redisson完成");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public Redisson getRedisson() {
        return this.redisson;
    }
}
